package com.ruoyi.web.controller.system;

import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.domain.DTO.AuditBO;
import com.ruoyi.common.core.domain.DTO.InsertWithdrawalRecordBO;
import com.ruoyi.common.core.domain.entity.WithdrawalRecord;
import com.ruoyi.framework.web.service.WithdrawalRecordService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.List;

@RestController
@RequestMapping("/withdrawal")
public class WithdrawalRecordController extends BaseController {
    @Autowired
    private WithdrawalRecordService withdrawalRecordService;

    // 提现申请
    @PostMapping("/apply")
    public AjaxResult apply(@RequestBody @Valid InsertWithdrawalRecordBO insertWithdrawalRecordBO) {
        withdrawalRecordService.insertWithdrawalRecord(insertWithdrawalRecordBO);
        return success();
    }

    // 根据用户id查询提现记录
    @GetMapping("/selectWithdrawalRecordByUserId/{userId}")
    public AjaxResult selectWithdrawalRecordByUserId(@PathVariable Long userId) {
        List<WithdrawalRecord> withdrawalRecordList = withdrawalRecordService.selectWithdrawalRecordByUserId(userId);
        return success(withdrawalRecordList);
    }

    // 查询所有提现记录
    @GetMapping("/selectWithdrawalRecordByUserId")
    public AjaxResult selectWithdrawalRecord() {
        List<WithdrawalRecord> withdrawalRecordList = withdrawalRecordService.selectWithdrawalRecordByUserId(null);
        return success(withdrawalRecordList);
    }

    //审核
    @PostMapping("/audit")
    public AjaxResult audit(@RequestBody @Valid AuditBO auditBO) {
        withdrawalRecordService.audit(auditBO);
        return success();
    }

    @PostMapping("/callback")
    public AjaxResult callback() {
        withdrawalRecordService.callback();
        return success();
    }
}
